package com.fun.feifun.job.handler;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fun.feifun.modules.business.constant.OrderPayStatusEnum;
import com.fun.feifun.modules.business.constant.OrderStatusEnum;
import com.fun.feifun.modules.business.model.BusinessOrder;
import com.fun.feifun.modules.business.service.IBusinessOrderService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author wukefei
 * @date $ $
 */
@Component
public class ReMatchOrderJobHandler implements Job {

    @Autowired
    private IBusinessOrderService orderService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //查询那些订单还在支付中
        QueryWrapper<BusinessOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BusinessOrder::getState, OrderStatusEnum.init.getValue());
        List<BusinessOrder> list = orderService.list(queryWrapper);
        if(list.isEmpty()){
            return;
        }
        for (BusinessOrder order: list) {
            orderService.reRouteOrder(order);
            //支付失败释放锁定金额。
        }

    }
}
